// 定时任务
import { getSchedule } from '@/services';
import { ISchedule } from '@/types';
import { Effect, Reducer } from 'umi';

export interface SysScheduleModelState {
    ScheduleList:ISchedule[];
    ScheduleLength:number
}

export interface SysScheduleModelType {
  namespace: 'Schedule';
  state: SysScheduleModelState;
  effects: {
    getSchedule:Effect
  };
  reducers: {
    save: Reducer<SysScheduleModelState>;
  };
}

const SysScheduleModel: SysScheduleModelType = {
  namespace: 'Schedule',

  state: {
    ScheduleList:[],
    ScheduleLength:0
  },

  effects: {
    // 查询
    *getSchedule({payload},{call,put}){
        let result = yield call(getSchedule,payload);
        if(result){
            yield put({
                type:"save",
                payload:{
                    ScheduleList:result.records.map((item:any)=>{
                        item.key = item.transportId;
                        return item;
                      })
                }
            })
        }
    }

    
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
    
  }
  
};

export default SysScheduleModel;